// pages/goods_detail/index.js
import {
  request
} from "../../request/index.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //商品详情数据
    goodsObj: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options, "商品详情页面")
    const {
      goods_id
    } = options
    this.getGoodsDetail(goods_id)
  },
  getGoodsDetail: function (goods_id) {
    request({
        url: "/goods/detail",
        data: {
          goods_id
        }
      })
      .then(res => {
        console.log(res, "商品详情")
        const result = res.data.message;
        this.setData({
          goodsObj: {
            goods_price: result.goods_price,
            goods_name: result.goods_name,
            goods_introduce: result.goods_introduce,
            pics: result.pics
          }
        })
      })

  },
  handlePreViewImage:function(event){
    //当前要放大的图片的url
    const currentUrl=event.currentTarget.dataset.url
    const urls=this.data.goodsObj.pics.map(v=>v.pics_mid)
    wx.previewImage({
      urls,
      current:currentUrl
    })
  }


})